package Ioc_DI;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;


import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 不止只有component能将了交给spring来管理，还有
 * Controller（控制层）
 * Server（业务逻辑层）
 * Repository（数据层）
 * Configuration（配置层）这些都可以将类交给spring管理
 * 他们的用处也是不同的
 * 这5个注解中，只有controller不可以和其他注解替换，控制层只能使用Controller
 * 配置层是觉得这代码不在前三层的话就用他，这些都是component的接口注解，都是基于component实现的
 */
@AllArgsConstructor
@NoArgsConstructor
@Component
public class Components {
    public String name;

    @Primary
    @Bean("c1")
    public Components c1() {
        Components c = new Components();
        c.name = "hhh";
        return c;
    }

    @Bean("c2")
    public Components c2() {
        Components c = new Components();
        c.name = "www";
        return c;
    }

    @Bean
    public String name1() {
        return "hadage";
    }

    @Bean
    public Components c3(String name1) {
        Components c = new Components(name1);
        return c;
    }

    public void p() {
        System.out.println("hello component");
    }
}

@Controller
class helloController {
    @Autowired
    helloService hS;

    public void p() {
        System.out.println("hello controller");
        hS.p();
    }
}

@Service
class helloService{
    public void p(){
        System.out.println("hello Service");
    }
}

@Configuration
class helloConfiguration{
    public void p(){
        System.out.println("hello Configuration");
    }
}

@Repository
class helloRepository{
    public void p(){
        System.out.println("hello Repository");
    }
}











